<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>定位</title>
  <style>
    div.nav {
      border:1px solid #aaa;
      width: 150px;
      height:50px;
    }
    #parent {
      height:400px;
      width: 400px;
      border:1px solid red;
      /* position: static; */
    }
    #child {
      height:200px;
      width:200px;
      border:1px solid green;
      /*相对于parent设置位置*/
      /* position: relative; */
      position: relative;
      top:20px;
      left:40px;
    }
    #top {
      padding:20px;
      border:1px solid #aaa;
      /* position: fixed; */
      top:0px;
      width: 100%;
    }
    #right {
      position: fixed;
      right:10px;
      top:50%;
    }
    #bottom {
      position: fixed;
      bottom:20px;

    }
    div.nav {
      /*容器中的子容器居中*/
      text-align: center;
    }
    div.nav span {
      position: relative;
      /* left:10px; */
      top:12px;
    }
  </style>
</head>
<body>
  <div id="top">
    永远在顶部
  </div>
  <div class="nav">
    <span>测试定位</span>
  </div>
  <div id="right">固定右边</div>

  <div id="parent">
    <div id="child">测试定位2/div>
  </div>
  <br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
  <div id="bottom"><a href="#top">返回顶部</a></div>
</body>
</html>